﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="PrintLabel2.aspx.cs" Inherits="PMS.UI.PM.PrintLabel2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        //通过分析模块内部进入，传了ID
        var Id = com.get.Id;
        var DetailData;
        var kValue = 0;
        var action = com.get.action;
        $(function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/Logic/PM/BottlePrintAjax.aspx?method=GetBottlePrintMainById",
                data: { ID: Id },
                asyn: false,
                success: function (data) {
                    console.log(data);
                    var per = data.per;
                    var quo = data.quo;
                    $("#lblGB").html(per.GBCode);
                    kValue = per.kValue;
                    $("#lblOrderNum").html(quo.OrderCode);

                    $("#lblSampleNum").html(per.BottleCode);
                    $("#GuiGE").html(quo.BottleVolume);
                    //获取有效日期
                    var d = new Date();
                    var newDate = (d.getFullYear() + 1) + "-" + (d.getMonth() + 1) + "-" + (d.getDate());

                    $("#iptDeadLine").datebox("setValue", newDate);
                    $("#lblBudgetPressure").html(per.Pressure + "MPa");
                    $("#lblInspector").html(per.AnalyseUserName);
                    if (action == "record") {
                        $("#lblDeadLine").html(per.DeadLine);
                        $("#iptDeadLine").datebox("destroy");
                    }

                    $("#selPrintColumn").val(per.PrintColumn);
                    $("#selPrintColumn").combobox({

                        data: [{ id: "1", text: "单栏打印" }, { id: "2", text: "双栏打印" }],
                        valueField: "id",
                        textField: "text",
                        panelHeight: 'auto',
                        onSelect: function (rec) {

                            LoadDetailData();
                        }

                    });

                    $("#selChiOrEng").val(per.PrintChiOrEng);
                    $("#selChiOrEng").combobox({

                        data: [{ id: "0", text: "分子式打印" }, { id: "1", text: "名称打印" }],
                        valueField: "id",
                        textField: "text",
                        panelHeight: 'auto',
                        onSelect: function (rec) {
                            LoadDetailData();
                        }

                    });



                    $("#selIsAir").val(per.PrintIsAir);
                    $("#selIsAir").combobox({

                        data: [{ id: "0", text: "非空气打印" }, { id: "1", text: "空气底气打印" }],
                        valueField: "id",
                        textField: "text",
                        panelHeight: 'auto',
                        onSelect: function (rec) {
                            LoadDetailData();
                        }

                    });



                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/Logic/PM/BottlePrintAjax.aspx?method=GetBottlePrintDetailById",
                        data: { ID: Id },
                        success: function (data) {
                            DetailData = data;
                            LoadDetailData();
                        }
                    });

                }
            });





            $("#btnPrint").click(function () {
                var printColumn = $("#selPrintColumn").combobox("getValue");
                var printChiOrEng = $("#selChiOrEng").combobox("getValue");
                var printIsAir = $("#selIsAir").combobox("getValue");
                try {
                    var date = $("#iptDeadLine").datebox("getValue");
                    $("#iptDeadLine").datebox("destroy");
                    $("#lblDeadLine").html(date);
                } catch (e) {

                }
                $("#divPrint").print({
                    globalStyles: true,//是否包含父文档的样式，默认为true
                    mediaPrint: false,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
                    stylesheet: null,//外部样式表的URL地址，默认为null

                    noPrintSelector: ".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
                    iframe: true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
                    append: null,//将内容添加到打印内容的后面
                    prepend: null,//将内容添加到打印内容的前面，可以用来作为要打印内容
                    deferred:
                 $.Deferred(

                        )//回调函数
                });
                if (action != "record") {
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/Logic/PM/BottlePrintAjax.aspx?method=SavePrintLabelContent",
                        data: {
                            ID: Id,
                            date: date,
                            url: "PrintLabel",
                            printColumn: printColumn,
                            printChiOrEng: printChiOrEng,
                            printIsAir: printIsAir
                        },
                        success: function (data) {
                            com.message(data.state, data.msg);
                        }

                    });
                }

            });
        })

    </script>
    <script type="text/javascript">
        function LoadDetailData(pringColumn) {

            var pringColumn = $("#selPrintColumn").combobox("getValue");
            var printChiOrEng = $("#selChiOrEng").combobox("getValue");
            var printIsAir = $("#selIsAir").combobox("getValue");

            var data = com.FillAir(DetailData, printIsAir);
            var content = "";
            var concen = "";
            var isMg3 = "";
            if (pringColumn == 1) {
                var fontSize = "20px";
            }
            else {
                var fontSize = "18px";
            }
            if (data.length == 1) {
                content += "<tr>";
                content += "<td style='font-size: " + fontSize + ";text-align:left'>";
                if (printChiOrEng == "0") {
                    content += com.ConvertLower(data[0].GasEngName);
                }
                else {
                    content += data[0].GasChiName;
                }

                content += " &nbsp;</td>";
                content += "<td style='font-size:" + fontSize + ";'>";
                content += "&ge;" + data[0].BudgetConcentration + " %";
                content += "</td>";
                content += "</tr>";
            }
            else {
                for (var i = 0; i < data.length; i++) {
                    if (i % pringColumn == 0) {
                        content += "<tr>";
                    }
                    content += "<td style='font-size: " + fontSize + ";text-align:left'>";
                    if (printChiOrEng == "0") {
                        content += com.ConvertLower(data[i].GasEngName);
                    }
                    else {
                        content += data[i].GasChiName;
                    }
                    content += " &nbsp; </td>";
                    content += "<td style='font-size:" + fontSize + ";' colspan='" + (3 - pringColumn) + "'>";

                    if (data[i].IsBottom == "0") {
                        if (data[i].PrintUnit == "0" && data[i].PrintConcentration == "0") {
                            content += ConvertUnit(data[i].Concentration, "ppm", data[i].PrintDigitNum) + " mol/mol";
                        }
                        else if (data[i].PrintUnit == "0" && data[i].PrintConcentration == "1") {
                            content += ConvertUnit(data[i].AnalyseConcentration, "ppm", data[i].PrintDigitNum) + " mol/mol";
                        }
                        else if (data[i].PrintUnit == "1" && data[i].PrintConcentration == "0") {
                            isMg3 = "1";
                            content += ConvertUnit(data[i].computeMGCM, "mg", data[i].PrintDigitNum);
                        }
                        else if (data[i].PrintUnit == "1" && data[i].PrintConcentration == "1") {
                            isMg3 = "1";
                            content += ConvertUnit(data[i].actualMGCM, "mg", data[i].PrintDigitNum);
                        }
                    }
                    else {
                        content += "余量";
                    }
                    content += "</td>";
                    if (i % 2 == pringColumn || i == data.length - 1) {
                        content += "</tr>";
                    }
                }
                if (isMg3 == "1") {
                    //$("#lblGBHZ").html("标物号");
                    $("#lblZfText").html("(在标准状态下)");
                }
            }


            $("#detailBody").html("");
            $("#detailBody").append(content);
        }


        function ConvertUnit(value, unit, printNum) {

            var num = new Number(value);
            result = "";
            if (unit == "ppm") {
                if (num > 0.1) {
                    result = num.toPrecision(printNum);
                    result = result + "%";
                }
                else {
                    num = num * 10000;

                    result = num.toPrecision(printNum);

                    result = result.toLocaleString() + "&times;10<sup>-6</sup>";
                }
            }
            else {
                //if (num > 1000) {
                //    result = (num / 100).toPrecision(printNum);
                //    result = result + "&times;10<sup>2</sup> mg/m<sup>3</sup>";
                //}
                //else {
                //    result = num.toPrecision(printNum);
                //    result = result + " mg/m<sup>3</sup>";
                //}
                result = num.toPrecision(printNum);
                result = result + " mg/m<sup>3</sup>";
            }
            return result;

        }



        //保留2位小数，如：2，还会保留2 不会补0
        function toDecimal2NoZero(x) {
            var f = Math.round(x * 100) / 100;
            var s = f.toString();
            return s;
        }

        //保留3位小数，如：2，还会保留2 不会补0
        function toDecimal3NoZero(x) {
            var f = Math.round(x * 1000) / 1000;
            var s = f.toString();
            return s;
        }


    </script>


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">

    <div id="divPrint">
        <div style="text-align: center; width: 422px; font-weight: 600">
            <span style="font-size: 24px">标&nbsp;&nbsp;准&nbsp;&nbsp;物&nbsp;&nbsp;质</span>

        </div>
        <table id="printTable" style="border-top: 2px solid; border-bottom: 2px solid; width: 422px">
            <tr style="border-bottom: 2px solid;">
                <td style="font-size: 20px" colspan="4">
                    <label style="font-size: 20px" id="lblGB"></label>
                    <%-- <label style="font-size: 20px" id="lblGBHZ">国标号</label>--%>
                </td>
                <%--          <td id="tdval" colspan="3">
                    

                </td>--%>
            </tr>
            <tr style="border-bottom-style: solid">
                <td style="font-size: 20px; width: 80px">单据编号</td>
                <td style="width: 110px">
                    <label style="font-size: 20px" id="lblOrderNum"></label>
                </td>
                <td style="text-align: right; width: 80px"></td>
                <td style="width: 110px"></td>

            </tr>

            <tr style="border-bottom-style: solid">
                <td style="font-size: 20px">样品编号</td>
                <td>
                    <label style="font-size: 20px" id="lblSampleNum"></label>
                </td>
                <td style="font-size: 20px; text-align: right">规格:</td>
                <td style="font-size: 20px">
                    <label style="font-size: 20px" id="GuiGE"></label>
                    L
                </td>

            </tr>
            <tr style="border-bottom-style: solid">
                <td style="font-size: 20px">有效日期</td>
                <td>
                    <label style="font-size: 20px" id="lblDeadLine"></label>
                    <input id="iptDeadLine" type="text" class="easyui-datebox" style="width: 100px" />
                </td>
                <td style="font-size: 20px; text-align: right">压力:</td>
                <td>
                    <label style="font-size: 20px" id="lblBudgetPressure"></label>
                </td>
            </tr>

        </table>
        <table style="border-bottom: 2px solid; width: 422px">
            <tr style="border-bottom-style: solid">
                <td style="font-size: 20px" colspan="4">组分含量

                    <label style="font-size: 20px" id="lblZfText"></label>
                </td>

            </tr>
            <tbody id="detailBody">
            </tbody>

            <tr>
                <td></td>
                <td></td>
                <td style="font-size: 20px">检验员：</td>
                <td>
                    <label style="font-size: 20px" id="lblInspector"></label>

                </td>
            </tr>
        </table>
        <table style="width: 422px">
            <tr>
                <td style="font-size: 15px">生产地址：杭州市余杭区仁和工业园区
                </td>
            </tr>

            <tr>
                <td style="font-size: 15px">联系电话：0571-88132888</td>
            </tr>
            <tr>
                <td style="font-size: 15px">销售网址：http://www.zjdzqt.com
                </td>
            </tr>
            <tr>
                <td style="font-size: 16px">杭州新世纪混合气体有限公司
                </td>
            </tr>
        </table>


    </div>
    <input type="button" id="btnPrint" value="打印" />
    <input id="selPrintColumn" name="selPrintColumn" style="width: 100px;" />
      <input id="selChiOrEng" name="selChiOrEng" style="width: 100px;" />
    <input id="selIsAir" name="selIsAir" style="width: 100px;" />
</asp:Content>
